<template>
  <div class="login">
    <el-form ref="form" :model="form" :rules="rules" class="form">
      <img class="logo" src="@/assets/common/login-logo.png" alt="">
      <el-form-item prop="mobile">
        <el-input
          v-model="form.mobile"
          prefix-icon="el-icon-user-solid"
          placeholder="请输入用户名"
        />
      </el-form-item>
      <el-form-item prop="password">
        <el-input
          v-model="form.password"
          prefix-icon="el-icon-lock"
          show-password
          placeholder="请输入密码"
          @keyup.native.enter="submit"
        />
      </el-form-item>
      <el-form-item>
        <el-button class="btn" type="primary" @click="submit">{{
          $t('login.login')
        }}</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { sysLogin } from '@/api/login'
export default {
  data() {
    return {
      form: {
        mobile: '13800000002',
        password: '123456'
      },
      rules: {
        mobile: [
          {
            required: true,
            message: '必填',
            trigger: 'change'
          },
          {
            pattern:
              /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/,
            message: '请输入正确手机号',
            trigger: '[change,blur]'
          }
        ],
        password: [
          {
            required: true,
            message: '必填',
            trigger: 'change'
          }
        ]
      }
    }
  },
  methods: {
    submit() {
      this.$refs.form.validate(async(result) => {
        if (result) {
          const res = await sysLogin(this.form)
          // 存储token
          this.$store.dispatch('user/setToken', res.data)
          // 成功提示
          this.$message.success('登录成功')
          // 跳转到的首页
          this.$router.push('/dashboard')
          // token vuex
          console.log(res)
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.login {
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: url('~@/assets/common/k1.png') no-repeat;
  background-size: cover;
  .form {
    height: 400px;
    // background-color: aquamarine;
    .logo {
      padding: 0 15px 20px 15px;
    }
    .btn {
      width: 100%;
      height: 60px;
      background-color: #eb7830;
      font-size: 24px;
      border: #eb7830;
      opacity: 0.8;
    }
    ::v-deep .el-input__inner {
      height: 55px;
      background-color: #f4f6fa;
      opacity: 0.8;
    }
    ::v-deep input::-webkit-input-placeholder {
      color: rgb(94, 80, 80);
    }
    ::v-deep .el-input__prefix,
    .el-input__suffix {
      color: #151814 !important;
    }
    ::v-deep .el-form-item__error {
      color: #fff !important;
    }
  }
}
</style>
